#!/usr/bin/python
# vim:fileencoding=utf8
"""
Тестирующий модуль.
"""

from unittest import TestCase, TestSuite, TestLoader, main

import article
import noun
import word
import verb


class TestNoun(TestCase):
    """
    Тест класса noun
    """        
    def setUp(self):
        self.human = noun.Noun('human')


    def test2str(self):
        self.assertEqual(self.human.to_string(), 'human')
        self.assertEqual(self.human.to_string(plurum=True), 'humans')


    def test_base_form(self):
        self.assert_(('student',{'plurum':True}) in noun.Noun.base_form('students'))
        self.assert_(('student',{'common':False}) in noun.Noun.base_form("student's"))
        self.assert_(('student',{'common':False, 'plurum':True}) in
                       noun.Noun.base_form("students'"))
        self.assert_(('student',{}) in noun.Noun.base_form("student"))
        self.assert_(('fox',{'plurum':True}) in noun.Noun.base_form("foxes"))

    def test_form_generation(self):
        self.assertEqual(frozenset(noun.Noun('apple').all_forms()),
                         frozenset(('apple', 'apples', "apple's", "apples'")))


class TestVerb(TestCase):
    """
    Тест класса verb
    """    
    def setUp(self):
        self.work = verb.Verb('work')
    
    def test2str(self):
        self.assertEqual(self.work.to_string(), 'work')
        self.assertEqual(self.work.to_string(person=3, plurum=False), 'works')
    
    def test_base_form(self):
        self.assert_(('love',{'plurum':False, 'person':3}) in
                      verb.Verb.base_form('loves'))
        self.assert_(('love',{}) in verb.Verb.base_form("love"))


class TestArticle(TestCase):
    """
    Тест Article
    """
    Article = article.Article
    def test2str(self):
        self.assertEqual(self.Article.to_string(), '')
        self.assertEqual(self.Article.to_string(definite=True), 'the')
        self.assertEqual(self.Article.to_string(definite=True, plurum=True), 'the')
        self.assertEqual(self.Article.to_string(definite=False), 'a')
        self.assertEqual(self.Article.to_string(definite=False, plurum=True), '')
        
    def test_base_form(self):
        self.assertEqual([('an',{'plurum':False, 'definite':False})],
                          self.Article.base_form('an'))
        self.assertEqual([('the',{'definite':True})],
                          self.Article.base_form('the'))
        self.assertEqual([], self.Article.base_form('she'))

def suite():
    nounSuite = TestLoader().loadTestsFromTestCase(TestNoun)
    verbSuite = TestLoader().loadTestsFromTestCase(TestVerb)
    articleSuite = TestLoader().loadTestsFromTestCase(TestArticle)
    return TestSuite((nounSuite, verbSuite, articleSuite))
        
if __name__ == '__main__':
    main()
